package com.zy.dp.singleton.example5;

import java.util.HashMap;
import java.util.Map;

public class OneExtend
{

	private final static String DEFAULT_PREKEY = "Cache";
	private static Map<String, OneExtend> map = new HashMap<String, OneExtend>();
	private static int num = 1;

	private final static int NUM_MAX = 3;

	private OneExtend()
	{

	}

	public static OneExtend getInstance()
	{
		String key = DEFAULT_PREKEY + num;

		OneExtend oneExtend = map.get(key);

		if (oneExtend == null)
		{
			oneExtend = new OneExtend();
			map.put(key, oneExtend);
		}

		num++;
		if (num > NUM_MAX)
		{
			num = 1;
		}

		return oneExtend;

	}

	public static void main(String[] args)
	{

		OneExtend t1 = OneExtend.getInstance();
		OneExtend t2 = OneExtend.getInstance();

		OneExtend t3 = OneExtend.getInstance();

		OneExtend t4 = OneExtend.getInstance();
		OneExtend t5 = OneExtend.getInstance();

		OneExtend t6 = OneExtend.getInstance();

		System.out.println("t1=" + t1);
		System.out.println("t2=" + t2);
		System.out.println("t3=" + t3);

		System.out.println("t4=" + t4);

		System.out.println("t5=" + t5);

		System.out.println("t6=" + t6);

	}

}
